<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="文件名称">
                <a-input v-model="queryParam.fileName" allow-clear placeholder="请输入文件名称" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="所属机构">
                <a-tree-select
                  v-model="queryParam.orgCode"
                  style="width: 100%"
                  :dropdownStyle="{ maxHeight: '300px', overflow: 'auto' }"
                  :treeData="orgTree"
                  placeholder="请选择机构"
                  treeDefaultExpandAll
                  @change="(e) => initOrgName(e)"
                >
                  <span slot="title" slot-scope="{ id }">{{ id }}</span>
                </a-tree-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>

    <a-card :bordered="false">
      <s-table ref="table" :columns="columns" :data="loadData" :rowKey="(record) => record.id">
        <template slot="operator">
          <!-- <a-button type="primary" icon="plus" @click="$refs.uploadModal.init()">新增</a-button> -->
          <a-upload name="file" :accept="accept" :customRequest="customRequest" :showUploadList="false">
            <a-button type="primary" :loading="excelUploadLoading" style="margin-left: 8px"> <a-icon type="upload" /> 新增 </a-button>
          </a-upload>
        </template>
      </s-table>

      <upload-modal ref="uploadModal" />
    </a-card>
  </div>
</template>

<script>
import { STable } from '@/components'
import { uploadStoreOrder, biStoreOrderPage } from '@/api/modular/main/order/businessOrderManage'
import { getOrgList, getOrgTree } from '@/api/modular/system/orgManage'
import uploadModal from '@/views/main/order/uploadModal'
export default {
  name: 'index',
  components: {
    STable,
    uploadModal,
  },
  data() {
    return {
      excelUploadLoading: false,
      accept: '.csv',
      tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
      orgTree: [],
      orgList: [],
      columns: [
        {
          title: '商户号',
          align: 'center',
          dataIndex: 'storeCode',
        },
        {
          title: '店铺名称',
          align: 'center',
          dataIndex: 'storeName',
        },
        {
          title: '省',
          align: 'center',
          dataIndex: 'provName',
        },
        {
          title: '市',
          align: 'center',
          dataIndex: 'cityName',
        },
        {
          title: '区/县',
          align: 'center',
          dataIndex: 'countryName',
        },
        {
          title: '交易金额',
          align: 'center',
          dataIndex: 'tradeAmount',
        },
        {
          title: '退款金额',
          align: 'center',
          dataIndex: 'refundAmount',
        },
        {
          title: '支付方式',
          align: 'center',
          dataIndex: 'paidWay',
        }
      ],
      loadData: (parameter) => {
        return biStoreOrderPage(Object.assign(parameter, this.queryParam)).then((res) => {
          return res.data
        })
      },
      queryParam: {},
    }
  },
  created() {
    this.getOrgDate()
  },
  methods: {
    // 导入excel
    customRequest(data) {
      const formData = new FormData()
      formData.append('file', data.file)
      this.excelUploadLoading = true
      uploadStoreOrder(formData)
        .then((res) => {
          if (res.success) {
            this.$message.success('导入excel成功')
          } else {
            this.$message.warning('导入excel失败')
          }
        })
        .finally(() => {
          this.excelUploadLoading = false
        })
    },
    getOrgDate() {
      getOrgTree().then((res) => {
        this.orgTree = res.data
      })
      getOrgList().then((res) => {
        this.orgList = res.data
      })
    },
    initOrgName(value) {},
  },
}
</script>

<style scoped>
</style>